<?php
require_once('model/Visitor.php');

class Visitor extends DataObjects_Visitor 
{
	
	/**
	 * Get all Visitor
	 *
	 * @return Visitor object
	 */
	public function getList($filter = array(), $pagination = true){
		
		$visitor = new Visitor();
		
		if($pagination){
			$p = new FRM_Pager('page',Parameter::$params["PAGING_DEFAULT_ITEM_PER_PAGE"], new FRM_Pager_RangeIterator(1, Parameter::$params['PAGING_DEFAULT_PAGE_DELTA'], 1));
			$visitor->setPager($p);
		}
		$visitor->orderBy('id');
		$visitor->find();
		
		return $visitor;
	}
	
	public function sendMail($visitor){
	
		$email_support = Parameter::$params['EMAIL_SUPPORT'];
	
		$from = Parameter::$params['EMAIL_SERVER'];
		$to = $visitor->email ;
	
		$headers  = 'MIME-Version: 1.0' . "\r\n";
		$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
	
		// Additional headers
		$headers .= 'To: '.$to . "\r\n";
		$headers .= 'From: '.$from. "\r\n";
		$subject = "You have chosen the garage on website";
	
		$smarty = FRM::load('smarty');
		$smarty->assign('visitor', $visitor);
	
		$message= $smarty->fetch('admin/email-invoice.html');
		return MailSMTP::send($to, $subject, $message);
	}

}
?>